﻿<?php
class Calendar extends CI_Model {
	var $err_code;
	var $err_msg;
	var $id;

    function __construct()
    {
        parent::__construct();
		if ($this->session->userdata('login'))
		{
			// 已经成功登陆
			$this->uid = $this->session->userdata('uid');
		}
    }

    //添加事件
    function insert($start_time,$end_time,$type,$repeat,$description,$appendix)
    {
     //检查权限

	
    //检查数据
    $data = $this->security->xss_clean($data);
   
     $data=array(
			'uid' => $uid
			'start_time' => $start_time
			'end_time' => $endtime
			'type' => $type
			'repeat' => $repeat
			'description' => $description
			'appendix' => $appendix
		);

		//输入数据库
		$this->db->insert('calendar',$data); 
		if(!$this->db->insert('calendar',$data))
		{
			$this->err_code = 101;
			$this->err_msg = '输入数据库失败';
			return FALSE
		}
		else
 		{
		      	$this->err_code = 0;
			$this->err_msg = 'Success';
			return $id
     }

     //删除事件
     function delete($id)
     {
		//检查权限

 
		//删除数据
		this->db->delete('calendar', array('id' => $id)); 
		if(!this->db->delete('calendar', array('id' => $id))
		{
			$this->err_code = 102;
			$this->err_msg = '删除数据失败';
			return FALSE
		}
	}

     //修改事件
     function change($start_time,$end_time,$type,$repeat,$descrption,$appendix)
     {
      //检查权限


      //检查数据
      $data = $this->security->xss_clean($data);

      $data = array(
	         'start_time' => $starttime
	         'end_time' => $endtime
                 'type' => $type
	         'type' => $type
	         'repeat' => $repeat
	         'description' => $description
	         'appendix' => $appendix
	        );
    
      //输入数据库
      $this->db->where('id', $id);
      $this->db->update('calendar', $data); 
      if(!$this->db->update('calendar', $data))
     {
      $this->err_code = 101;
      $this->err_msg = '输入数据库失败';
      return FALSE
     }

      //获取事件列表
      function get_list($id)
      {
       //检查权限

       //获取数据
       $querry = $this->db->get('calendar', 10, 30);
       $this->db->order_by($querry->'title', "desc"); 
       echo $querry->'title'
      
        if(!echo $querry->title)
        {
         $this->err_code = 103;
         $this->err_msg = '获取事件列表失败';
         return FALSE
        }
        else
         {
	  $this->err_code = 0;
          $this->err_msg = 'Success';
          return $querry->title;
	 }

  	//获取个人日历事件
	$query = $this->db->get_where('calendar', array('uid' => $uid));
	$q = $query->result_array();

	//获取用户隶属关系
        $querry = $this->db->get_where('user_sub', array('uid' => $uid));
	$gid = $querry->result_array->'gid'

	//获取学术日历和行政日历事件
	$query = $this->db->get_where('calendar', array('uid' => $gid));
	$t = $query->result_array();

	//检查提醒
	switch ($q['remind'])
	{
	 case1: $q['remind'] = 1
	   echo '你有1天后的事件需要提醒' 
	 case2: $q['remind'] = 2
	   echo '你有2天后的事件需要提醒'
	 case3: $q['remind'] = 3
	   echo '你有3天后的事件需要提醒'
	 case4: $q['remind'] = 4
	   echo '你有4天后的事件需要提醒'
	 case5: $q['remind'] = 5
	   echo '你有5天后的事件需要提醒'
	 case6: $q['remind'] = 6
	   echo '你有6天后的事件需要提醒'
	 case7: $q['remind'] = 7
	   echo '你有7天后的事件需要提醒'
	 case8: $q['remind'] = 0
	   echo '你有今天的事件需要处理'
        }




        /*返回错误码*/
	function get_err_code()
	{
	  return $this->err_code;
	}
	
	/*返回错误信息*/
	function get_err_msg()
	{
	  return $this->err_msg;
	}

}
/*End of file user.php*/
























}
